Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Switch - Dynamic properties #1227

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

bartbutenaers
Copy link
Contributor

Description

This PR allows the properties of a ui-switch to be dynamically updated via input messages:

  • Label: msg.ui_update.label
  • Passthrough: msg.ui_update.passthru
  • Indicator: msg.ui_update.decouple
  • On Color: msg.ui_update.oncolor
  • Off Color: msg.ui_update.offcolor
  • On Icon: msg.ui_update.onicon
  • Off Icon: msg.ui_update.officon

Example flow

[{"id":"bc5ab21a6466fac2","type":"ui-switch","z":"4aad778b57d4f47b","name":"","label":"Test switch","group":"c2bf863890b3eab0","order":1,"width":0,"height":0,"passthru":false,"decouple":false,"topic":"topic","topicType":"msg","style":"","className":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":1090,"y":520,"wires":[["f659839079aa4ede"]]},{"id":"61e277319d8b55f0","type":"inject","z":"4aad778b57d4f47b","name":"on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":890,"y":520,"wires":[["bc5ab21a6466fac2"]]},{"id":"9dc929aaec47933b","type":"inject","z":"4aad778b57d4f47b","name":"off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":890,"y":560,"wires":[["bc5ab21a6466fac2"]]},{"id":"f659839079aa4ede","type":"debug","z":"4aad778b57d4f47b","name":"debug 2527","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":520,"wires":[]},{"id":"e31947f63eb055e1","type":"inject","z":"4aad778b57d4f47b","name":"Another label","props":[{"p":"ui_update","v":"{\"label\": \"Another label\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":870,"y":620,"wires":[["bc5ab21a6466fac2"]]},{"id":"d6de44def3705677","type":"inject","z":"4aad778b57d4f47b","name":"Custom icons","props":[{"p":"ui_update","v":"{\"onicon\":\"toggle-switch-outline mdi-48px\",\"oncolor\":\"green\",\"officon\":\"toggle-switch-off mdi-48px\",\"offcolor\":\"red\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":870,"y":680,"wires":[["bc5ab21a6466fac2"]]},{"id":"7ead5d69fbe9853d","type":"inject","z":"4aad778b57d4f47b","name":"Default icons","props":[{"p":"ui_update","v":"{\"onicon\":\"\",\"oncolor\":\"\",\"officon\":\"\",\"offcolor\":\"\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":870,"y":720,"wires":[["bc5ab21a6466fac2"]]},{"id":"0a1008400a479523","type":"inject","z":"4aad778b57d4f47b","name":"Show input state","props":[{"p":"ui_update","v":"{\"decouple\": true}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":860,"y":780,"wires":[["bc5ab21a6466fac2"]]},{"id":"ecf7957217391100","type":"inject","z":"4aad778b57d4f47b","name":"Show output state","props":[{"p":"ui_update","v":"{\"decouple\": false}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":850,"y":820,"wires":[["bc5ab21a6466fac2"]]},{"id":"c2bf863890b3eab0","type":"ui-group","name":"Ui switch demo","page":"2e8fc9a730774265","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"2e8fc9a730774265","type":"ui-page","name":"Demo","ui":"be29745a6e568f30","path":"/page11","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":1,"className":"","visible":"true","disabled":"false"},{"id":"be29745a6e568f30","type":"ui-base","name":"UI Name","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control","ui-chart","ui-text-input","ui-dropdown"],"showPathInSidebar":false,"titleBarStyle":"default"},{"id":"a965ccfef139317a","type":"ui-theme","name":"Default","colors":{"surface":"#404040","primary":"#109fbc","bgPage":"#e8e8e8","groupBg":"#d6d6d6","groupOutline":"#6fbc10"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

dynamic_switch

TODO's

image

When I first saw the "Indicator" property in the config screen this week, I thought that it was only about the node status label. But it seems that there is a quite simple but powerfull mechanism involved behind the scenes. I really like the simplicity of the design! But it is not clear what this property is really doing, by simply looking at the config screen. So I suggest to update the documenation.

Moreover the property is named "Indicator" on the config screen. On the other hand, the corresponding node property is decouple. First at all I find it confusing that the dynamic property has a different name as in the config screen. Imho I would call it also 'Decouple' on the config screen, because it is in fact a decoupling mechanism.

I think this is the summary:

  • Decoupled = True: Visual state changes immediately when clicked.
  • Decoupled = False: Visual state changes only after input message.

But since I am not native english speaking you guys might perhaps have better descriptions for this...

Related Issue(s)

See #1181

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production

Labels

  • Includes a DB migration? -> add the area:migration label

Copy link
Contributor

@gayanSandamal gayanSandamal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bartbutenaers thanks a lot for improvement of this widget

Dynamic properties are working as expected and the docs also looks good.

Screen.Recording.2024-08-26.at.11.09.20.mov

Overall PR looks good to me.

@joepavitt are we setting Passthru as a dynamic property #1181. It's not implemented other widgets at the moment

@@ -113,7 +136,7 @@ export default {
},
toggle () {
if (this.state.enabled) {
if (this.props.decouple) {
if (this.getProperty('decouple')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move this to a computed property and refer it here as a readability improvement. But we can do that later

computed: {
    decouple () {
        return this.getProperty('decouple')
    }
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we setting Passthru as a dynamic property #1181. It's not implemented other widgets at the moment

It wasn't a priority in others, switch is used in different ways where having this would be useful. Not goign to push it away if it's already been implemented!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback Joe. I will check this separately

@joepavitt joepavitt merged commit 95f83e6 into FlowFuse:main Aug 27, 2024
1 of 2 checks passed
@joepavitt joepavitt changed the title switch dynamic properties UI Switch - Dynamic properties Aug 27, 2024
@bartbutenaers
Copy link
Contributor Author

Hi @joepavitt, @joepavitt,
Thanks for taking the time to review this!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants